<?php 
    $theme_id =  -1;
    $theme_id = Configure::read('App.themes.site_current');
    if(!empty($theme_id)){
      $theme_id = $theme_id['sub_sites']['themes']['id'];                
    } 
    $is_Administrator = Configure::read('Is_Administrator');    
?>
<?php echo $this->Form->create('Paginate', array('id' => 'paginate', 'url' => $this->request->here(false), 'type' => 'post', 'inputDefaults' => array('label' => false))); ?>           				
<div id="content-header">
    <h1><?php echo __d('system','Content Management');?></h1>
</div>
<div id="breadcrumb">
    <a href="<?php echo $this->Html->url('/admin/')?>" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> <?php echo __d('system','Home');?></a>
    <a href="#" class="current"><?php echo __d('system','List Contents');?></a>
</div>
<div class="container-fluid">
<div class="row-fluid">
    <div class="span12">
        <?php     echo $this->element('toolbar');?>	               
        <?php echo $this->Session->flash(); ?> 							
        <div class="widget-box">
            <div class="widget-title">
                <span class="icon">
                    <i class="icon-th"></i>
                </span>
                <h5><?php echo __d('system','List of content');?></h5>
            </div>
            <!--For manage node normal-->
                <div class="widget-content widget-content-two">
                <div class="wd-select">
                    <div class="control-group">
                        <div class="controls wd-farming">
                            <select>
                                <option /><?php echo __d('system','Delete');?>
                            </select>                            
                            <?php 
                                if($id==Image_active):
                                    echo $this->Form->input('show_home',array(
                                            'type'=>'select',
                                            'name'=>'data[Paginate][show_home]',
                                            'div'=>false,
                                            'label'=>false,
                                            'default'=>$default_show,
                                            'options'=>array(0=>__d('system','Show all image'),1=>__d('system','Show is home'))
                                        ));
                               endif;
                            ?>                                                                                     
                            <button class="btn"><?php echo __d('system','Apply');?></button>
                            <?php if($id==Category_Question):?>
                                <a class="btn" href="/admin/node/node/add_question.html?continue=%2Fvie%2Fadmin%2Fnode%2Fnode%2Fmanage_question.html%3Fsimple_active%3Dmanage_question" target="_blank"><?php echo __d('system','Add Question');?></a>
                            <?php endif;?>
                        </div>
                    </div>
                </div>
                <table class="table table-bordered data-table table-striped with-check wd-hover-btn">
                    <thead>
                        <tr>
                            <th><input type="checkbox" id="title-table-checkbox" name="title-table-checkbox" /></th>
                            <th> <?php echo  __d('system', 'Title'); ?></th>
                            <?php if($id==News):?>
                                <th> <?php echo  __d('system', 'Comments'); ?></th>
                            <?php endif;?>
                            <th> <?php echo  __d('system', 'Author'); ?></th>
                            <th> <?php echo  __d('system', 'Categories'); ?></th>
                            <th> <?php echo  __d('system', 'Translate'); ?></th>
                            <th class="wd-fix-width-1"><?php echo  __d('system', 'Last update'); ?></th>
                            <th class="wd-fix-width-2"><?php echo  __d('system', 'Action'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php

                            $defaultLanguage = Router::defaultLanguage();
                            $_queries = array('continue' => $this->request->here(false));
                        ?> 
                        <?php foreach ($listNodes as $node) : ?>                                            
                            <tr>
                                <td><input type="checkbox" name="data[Paginate][chk_node_type][]" value="<?php echo $node['Node']['id'];?>"/></td>            
                                <?php if (isset($_displayFields['title'])): ?>       
                                    <td>
                                        <a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'edit', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>"> <?php echo $node['Node']['title']; ?></a>
                                    </td>
                                <?php endif; ?>
                                <?php if($id==News):?>       
                                    <td>
                                        <?php 
                                               $node_id = $node['Node']['id'];         
                                               $comment = ClassRegistry::init('View.Comment')->find('count',array('conditions'=>array('Comment.node_id'=>$node_id,'Comment.status'=>1)));
                                               if(!empty($comment)){
                                                   echo intval($comment);            
                                               }else{echo 0;}
                                        ?>
                                    </td>
                                <?php endif; ?>
                                <?php if (isset($_displayFields['user_id'])): ?>       
                                    <td>
                                        <?php echo $node['User']['fullname']; ?>
                                    </td>
                                    <?php endif; ?>
                                <?php if (isset($_displayFields['node_type_id'])): ?>       
                                    <td>
                                        <a href="#">  <?php echo $node['NodeType']['name']; ?></a>
                                    </td>
                                    <?php endif; ?>    
                                <td>
                                    <?php if (isset($_translateMaps)): ?>
                                        <ul class="wd-laguage">
                                            <?php
                                                foreach (Configure::read('Languages') as $_language) {
                                                    if ($_language['code'] === $defaultLanguage) {
                                                        continue;
                                                } ?>
                                                <?php 
                                                    if(empty($_language['path'])){
                                                        $flags = 'flags_default.png';                                                
                                                    }
                                                    else{$flags = $_language['path'];}                                                                                        
                                                ?>
                                                <li><?php  echo $this->Html->link($this->Html->image('/img/' .$flags), array('plugin'=>'node','controller'=>'node','action' => 'translate', $node['Node']['id'], $_language['code'], '?' => $_queries), array(
                                                            'class' => isset($_translateMaps[$node['Node']['id']][$_language['locale']]) ? '' : 'ui-state-disabled', 'escape' => false, 'title' => $_language['name']));?></li>           
                                                <?php }?>
                                        </ul>
                                        <?php endif; ?>  
                                </td>
                                <?php if (isset($_displayFields['updated'])): ?>       
                                    <td>
                                        <?php echo date("d-m-Y g:i A",$node['Node']['updated']); ?>
                                    </td>
                                    <?php endif; ?>  
                                <td>
                                    <ul class="wd-link-control">
                                        <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'edit', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>" class="btn btn-mini"><i class="icon-edit"></i> <?php echo __d('system','Edit');?></a></li>
                                        <?php if($node['NodeType']['allow_share']==1):?>
                                            <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'send_mail', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>" class="btn btn-mini"><i class="icon-edit"></i> <?php echo __d('system','Send Mail');?></a></li> 
                                        <?php endif;?> 
                                        <?php if($theme_id != Themes_Default):?>                                       
                                            <li><a href="#share_<?php echo $node['Node']['id']?>" data-toggle="modal" class="btn btn-mini"><i class="icon-edit"></i> <?php echo __d('system','Share');?></a></li>                                                                        
                                        <?php endif;?>
                                        <li><a href="#<?php echo $node['Node']['id']?>" data-toggle="modal" class="btn btn-mini"><i class="icon-remove"></i> <?php echo __d('system','Delete');?></a></li>                            
                                        <?php if($node['Node']['node_type_id']==News||$node['NodeType']['kind_node_type_id']==kind_news||$node['NodeType']['id']==177):?>
                                            <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'mn_comment', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>" class="btn btn-mini"><i class="icon-remove"></i> <?php echo __d('system','Comments');?></a></li>
                                            <?php endif;?>
                                    </ul>
                                </td>
                            </tr>

                            <?php endforeach?>                        
                    </tbody>
                    <?php foreach ($listNodes as $node) : ?> 
                        <div id="<?php echo $node['Node']['id']?>" class="modal hide">
                            <div class="modal-header">
                                <button data-dismiss="modal" class="close" type="button">×</button>
                                <h3><?php echo __d('system','Alert modal');?></h3>
                            </div>
                            <div class="modal-body">
                                <p><?php echo __d('system','Are you sure delete');?> “<?php echo $node['Node']['title']?>”?</p>
                            </div>
                            <div class="modal-footer">
                                <a data-dismiss="modal" class="btn" href="#"><?php echo __d('system','Cancel');?></a>
                                <?php echo $this->Html->link(__d('system','Delete'), array('plugin'=>'node','controller' => 'node','action' => 'delete_list_index', '?' => array_merge($_queries, array('keys' => array($node['Node']['id']),'_here'=>$this->request->here))), array('title' => false, 'class' => 'btn btn-danger','data-dismiss='=>'modal')); ?>                        
                            </div>
                        </div>  
                        <div id="share_<?php echo $node['Node']['id']?>" class="modal hide">
                            <div class="modal-header">
                                <button data-dismiss="modal" class="close" type="button">×</button>
                                <h3><?php echo __d('system','Alert modal');?></h3>
                            </div>
                            <div class="modal-body">
                                <p><?php echo __d('system','Are you sure share node');?> “<?php echo $node['Node']['title']?>”?</p>
                            </div>
                            <div class="modal-footer">
                                <a data-dismiss="modal" class="btn" href="#"><?php echo __d('system','Cancel');?></a>
                                <?php echo $this->Html->link(__d('system','Share'), array('plugin'=>'node','controller' => 'node','action' => 'move_node', '?' => array_merge($_queries, array('keys' => array($node['Node']['id']),'kind_node_type'=>$node['NodeType']['kind_node_type_id'],'_here'=>$this->request->here))), array('title' => false, 'class' => 'btn btn-danger','data-dismiss='=>'modal')); ?>                        
                            </div>
                        </div>
                    <?php endforeach?>
                </table>
                <div class="wd-select">
                    <div class="control-group">
                        <div class="controls wd-farming">
                            <select>
                                <option /><?php echo __d('system','Delete');?>
                            </select>                                                        
                            <button class="btn"><?php echo __d('system','Apply');?></button>
                        </div>
                    </div>
                </div>								
            </div>
            <!--End-->
            <!--For manage node move-->
            <?php                        
            if($theme_id == Themes_Default)
            {
            ?>
                <div class="widget-content widget-content-two">
                <div class="wd-select">
                    <div class="control-group">
                        <div class="controls wd-farming">
                            <span class="lbl-moved"><?php echo __d('system','Thông tin được chuyển từ các phòng ban khác');?></span>
                        </div>
                    </div>
                </div>
                <table class="table table-bordered data-table table-striped with-check wd-hover-btn">
                    <thead>
                        <tr>                            
                            <th style="min-width: 450px"> <?php echo  __d('system', 'Title'); ?></th>                                                                                    
                            <th class="wd-fix-width-1"><?php echo  __d('system', 'Last update'); ?></th>
                            <th class="wd-fix-width-2"><?php echo  __d('system', 'Action'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php

                            $defaultLanguage = Router::defaultLanguage();
                            $_queries = array('continue' => $this->request->here(false));
                        ?> 
                        <?php foreach ($moveNodes as $node) :?>                                            
                            <tr>                                
                                <?php if (isset($_displayFields['title'])): ?>       
                                    <td>
                                        <a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'edit', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>"> <?php echo $node['Node']['title']; ?></a>
                                    </td>
                                    <?php endif; ?>                                                                   
                                <?php if (isset($_displayFields['updated'])): ?>       
                                    <td>
                                        <?php echo date("d-m-Y g:i A",$node['Node']['updated']); ?>
                                    </td>
                                    <?php endif; ?>  
                                <td>                                
                                    <ul class="wd-link-control">
                                        <?php if($is_Administrator):?>
                                            <li><a href="<?php echo $this->Html->url(array('plugin'=>'node','controller' => 'node', 'action' => 'edit', $node['Node']['node_type_id'], $node['Node']['id'], '?' => $_queries));?>" class="btn btn-mini"><i class="icon-edit"></i> <?php echo __d('system','Edit');?></a></li>
                                            <li><a href="#del_<?php echo $node['MoveNode']['node_id']?>" data-toggle="modal" class="btn btn-mini"><i class="icon-remove"></i> <?php echo __d('system','Delete');?></a></li>                            
                                            <li><a href="#<?php echo $node['Node']['id']?>" data-toggle="modal" class="btn btn-mini"><i class="icon-remove"></i> <?php echo __d('system','Not Received');?></a></li>                                                                    
                                        <?php endif;?>
                                    </ul>
                                </td>
                            </tr>

                            <?php endforeach?>                        
                    </tbody>
                    <?php foreach ($moveNodes as $node) : ?> 
                        <div id="<?php echo $node['Node']['id']?>" class="modal hide">
                            <div class="modal-header">
                                <button data-dismiss="modal" class="close" type="button">×</button>
                                <h3><?php echo __d('system','Alert modal');?></h3>
                            </div>
                            <div class="modal-body">
                                <p><?php echo __d('system','Are you sure not Received');?> “<?php echo $node['Node']['title']?>”?</p>
                            </div>
                            <div class="modal-footer">
                                <a data-dismiss="modal" class="btn" href="#"><?php echo __d('system','Cancel');?></a>
                                <?php echo $this->Html->link(__d('system','Not Received'), array('plugin'=>'node','controller' => 'node','action' => 'not_received_multiple', '?' => array_merge($_queries, array('keys' => array($node['MoveNode']['id']),'model'=>'MoveNode','plugin'=>'Node','linkAction'=>'admin_list_index'))), array('title' => false, 'class' => 'btn btn-danger','data-dismiss='=>'modal')); ?>                        
                            </div>
                        </div>  
                    <?php endforeach?>
                    <!--For delete node-->
                        <?php foreach ($moveNodes as $node) : ?> 
                            <div id="del_<?php echo $node['MoveNode']['node_id'];?>" class="modal hide">
                                <div class="modal-header">
                                    <button data-dismiss="modal" class="close" type="button">×</button>
                                    <h3><?php echo __d('system','Alert modal');?></h3>
                                </div>
                                <div class="modal-body">
                                    <p><?php echo __d('system','Are you sure delete');?> “<?php echo $node['Node']['title']?>”?</p>
                                </div>
                                <div class="modal-footer">
                                    <a data-dismiss="modal" class="btn" href="#"><?php echo __d('system','Cancel');?></a>
                                    <?php echo $this->Html->link(__d('system','Delete'), array('plugin'=>'node','controller' => 'node','action' => 'delete_list_index', '?' => array_merge($_queries, array('keys' => array($node['MoveNode']['node_id']),'_here'=>$this->request->here))), array('title' => false, 'class' => 'btn btn-danger','data-dismiss='=>'modal')); ?>                        
                                </div>
                            </div>  
                        <?php endforeach?>
                    <!--End-->
                </table>
                <div class="wd-select">
                    <div class="control-group">
                        <div class="controls wd-farming">
                            <select>
                                <option /><?php echo __d('system','Delete');?>
                            </select>                                                        
                            <button class="btn"><?php echo __d('system','Apply');?></button>
                        </div>
                    </div>
                </div>                                
            </div>
            <?php 
            }
            ?>
            <!--End-->
        </div>
    </div>	    
</div>
<?php         
    echo $this->Form->hidden('task', array('id' => 'task', 'value' => ''));
    echo $this->Form->end();
?>
<style type="text/css">
    .lbl-moved{text-decoration: underline;text-indent: initial;font-size: 16px;font-weight: bold;}
</style>